#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2009-1-24 上午08:21:50 
#Create By: Fla.sam
#
#DESC: 
#
#-------------------------------------------------

from CoreApp.models import UserProfile
from django import template, template

register = template.Library()

NAV_BAR = ( 
           ( ( '/home', u'Home' ), \
                    ( ( '/news', u'u6u8新闻' ), ) ), \
           ( ( '/user-manage', u'用户管理' ), \
                    ( ( 'add-user', u'添加新用户' ), \
                      ( '', u'查看用户资料' ), \
                      ( '/place/add', u'添加地理位置' ), \
                      ( '/place/view', u'查看地理位置' ), \
                      ( '/ann', u'用户公告' ) ) ),
           ( ( '/nav-manage', u'导航页管理' ), \
                    ( ( 'add-nav-url', u'添加导航Url' ), \
                      ( 'view-nav-url', u'查看导航Url' ), \
                      ( 'add-nav-label', u'添加导航分类页' ), \
                      ( 'view-nav-label', u'查看导航分类页' ), \
                      ( 'add-nav-tag', u'添加导航标签' ), \
                      ( 'view-nav-tag', u'查看导航标签' ) ) ), \
           ( ( '/desktop-manage', u'桌面业务管理' ), \
                    ( ( 'add-dt-ie-home', u'添加桌面IE首页' ), \
                      ( 'view-dt-ie-home', u'查看桌面IE首页' ), \
                      ( 'add-dt-url', u'添加桌面Url图标' ), \
                      ( 'view-dt-url', u'查看桌面Url图标' ), \
                      ( 'add-dt-wallpaper', u'添加桌面壁纸' ), \
                      ( 'view-dt-wallpaper', u'查看桌面壁纸' ) ) ), \
           ( ( '/history', u'历史浏览' ), \
                    ( ( 'nav-hit-count', u'导航页Url点击统计' ), \
                      ( 'nav-search-count', u'导航页SearchUrl统计' ), \
                      ( 'view-payback-history', u'用户返款历史' ) ) ), \
            ( ( '/account', u'我的U6U8' ), \
                    ( ( 'profile', u'修改我的资料' ), \
                      ( 'chpassword', u'修改密码' ), \
                      ( 'message', u'站内私信' ), \
                      ( 'u-point', u'U-Point' ) ) ),
           )
    
@register.inclusion_tag( 'top_nav_bar.html' )
def show_nav_bar( request ):
    
    class nav_object:
    
        def __init__( self ):
            self.link = ''
            self.title = ''
            self.is_active = False
            
    curr_path = request.path
    top_navs = []
    for x, y in NAV_BAR:
        top = nav_object()
        top.link = x[0]
        top.title = x[1]
        top.is_active = curr_path.startswith( top.link )
        top_navs.append( top )
        if top.is_active:
            sec_navs = []
            for i in y:
                sec = nav_object()
                if i[0].startswith( '/' ):
                    sec.link = i[0]
                else:
                    sec.link = top.link + '/' + i[0]
                sec.title = i[1]
                sec_navs.append( sec )
        
    return {'top_navs':top_navs, 'sec_navs':sec_navs}
